<?php
/*
 +----------------------------------------------------------------------
 + Title        : Login 控制器
 + Author       : Randy_chen
 + Version      : V1.0.0.1
 + Initial-Time : 2019/8/9 15:52
 + Last-time    : 2019/8/9 15:52+ 86187
 + Desc         : Login
 +----------------------------------------------------------------------
*/


namespace app\admin\controller;


use app\admin\service\LoginService;
use app\common\lib\exception\ApiException;
use think\Db;
use think\Exception;

class Login extends Base
{
    //登录
    public function login(){
        $service = new LoginService();

        try {
            $res = $service->login();
            if($res){
                $this->success($res);
            }else{
                $this->error(1,'登录失败!!');
            }
        } catch (ApiException $e) {
            $this->error($e->getCode() , $e->getMessage());
        } catch (Exception $e) {
            $this->error($e->getCode() , $e->getMessage());
        }
    }

    public function sys(){
	    $data = Db::name('sys_config')
	              ->select();
	    $this->returnSuccess($data);
    }

    //获取用户权限
    public function getUserInfo(){
        $auth = Db::name('sys_menu')->select();
        $data['userid'] = 1;
        $data['username'] = 'admin';
	    $data['menuList'] = $auth;
	    $data['authList'] = Db::name('sys_auth_node')
	                          ->where('auth', 1)
	                          ->column('node');
	    $this->returnSuccess($data);
    }
}